/**
* Copyright (c) 2022 - present TinyVue Authors.
* Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

@import '../custom.less';

@grid-checkbox-prefix-cls: ~'@{css-prefix}grid-checkbox';

// 表格内部多选框
.@{grid-checkbox-prefix-cls} {
  display: inline-block;
  user-select: none;
  cursor: pointer;

  & + & {
    margin-left: 10px;
  }

  > input {
    display: none;

    & + .@{grid-checkbox-prefix-cls}__icon {
      position: relative;
      display: block;
      width: var(--tv-Grid-icon-size);
      height: var(--tv-Grid-icon-size);
      border-radius: var(--tv-Grid-checkbox-border-radius);
      font-size: var(--tv-Grid-font-size);

      & + .@{grid-checkbox-prefix-cls}__label {
        display: none;
      }

      > svg {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        fill: var(--tv-Grid-checkbox-icon-color);
        font-size: var(--tv-Grid-checkbox-icon-size);
        path:last-child {
          fill: var(--tv-Grid-unchecked-border-color);
        }
        &:hover {
          path:last-child {
            fill: var(--tv-Grid-unchecked-border-color-hover);
          }
        }

        &.icon-checked-sur {
          display: none;
        }
      }
    }

    &:checked + .@{grid-checkbox-prefix-cls}__icon {
      & + .@{grid-checkbox-prefix-cls}__label {
        color: var(--tv-Grid-text-color);
      }

      > svg {
        &.icon-check {
          display: block;
        }

        &.icon-checked-sur {
          display: block;

          path:first-child {
            fill: var(--tv-Grid-bg-color-active);
          }

          path:last-child {
            fill: var(--tv-Grid-border-color-inverse);
          }
        }
      }
    }

    &:not(:checked) + .@{grid-checkbox-prefix-cls}__icon {
      .icon-check {
        path:first-child {
          fill: transparent;
        }
      }
    }
  }

  &.is__indeterminate {
    > input {
      &:not(:checked) {
        & + .@{grid-checkbox-prefix-cls}__icon {
          border: none;

          > svg {
            &.icon-half-select {
              path:first-child {
                fill: var(--tv-Grid-bg-color-active);
              }

              path:last-child {
                fill: var(--tv-Grid-border-color-inverse);
              }
            }
          }
        }
      }
    }
  }

  &.is__disabled:not(.is__indeterminate) {
    cursor: not-allowed;

    > input {
      & + .@{grid-checkbox-prefix-cls}__icon {
        > svg {
          fill: var(--tv-Grid-checkbox-border-color-disabled);
        }
        & + .@{grid-checkbox-prefix-cls}__label {
          color: var(--tv-Grid-checkbox-border-color-disabled);
        }
      }

      &:checked + .@{grid-checkbox-prefix-cls}__icon {
        > svg {
          path:first-child {
            fill: var(--tv-Grid-checked-disabled-bg-color);
          }

          path:nth-child(2) {
            fill: var(--tv-Grid-icon-inverse-disabled);
          }
        }
      }
    }
  }

  &.is__disabled.is__indeterminate {
    cursor: not-allowed;

    > input {
      & + .@{grid-checkbox-prefix-cls}__icon {
        > svg {
          fill: var(--tv-Grid-checkbox-border-color-disabled);
        }
      }

      & + .@{grid-checkbox-prefix-cls}__icon {
        svg.icon-half-select {
          path:first-child {
            fill: var(--tv-Grid-checked-disabled-bg-color);
          }

          path:nth-child(2) {
            fill: var(--tv-Grid-icon-inverse-disabled);
          }
        }
      }
    }
  }
  &.is__disabled > input:not(:checked) + .tiny-grid-checkbox__icon .icon-check {
    path:first-child {
      fill: var(--tv-Grid-bg-color-disabled);
    }

    path:nth-child(2) {
      fill: var(--tv-Grid-border-color-disabled);
    }

    &:hover {
      path:last-child {
        fill: var(--tv-Grid-unchecked-border-color);
      }
    }
  }

  & &__label {
    padding-left: 5px;
    vertical-align: middle;
    display: inline-block;
  }
}
